package com.zhangshuo.patternDesign.flyweight;

import java.util.Arrays;

/**
 * Created by shuo.zhang on 2017-10-27.
 *
 * 这个是英雄的基类，包含所有的通用方法
 *
 */
public abstract class AbstractHero {


    //英雄名字
    private String name;
    //技能
    protected String[] skills;


    /**
     * 初始化技能
     */
    abstract void  initSkills();


    public AbstractHero(String name){
        this.name = name;
        this.initSkills();
        this.checkSkills();
    }

    /**
     * 检查技能
     */
    private void checkSkills() {

        if(skills.length != 4)
            throw new RuntimeException("技能初始化失败");

        if (Arrays.stream(skills).filter((str) ->
            !(null == str || str.trim().length() == 0)
        ).count() != skills.length)
            throw new RuntimeException("技能初始化失败");
    }

    /**
     * 释放指定的技能
     * @param index
     */
    public void realeaseSkill(int index){
        if (index < 0)
            index =0;
        else if(index > skills.length -1)
            index = skills.length -1;
        System.out.println(this.name +"释放技能" + skills[index]);
    }


    /**
     * 释放普通攻击技能
     */
    public void commonAttack() {
        System.out.println(this.name + "释放普通攻击");
    }
}
